import { Injectable } from '@angular/core';
import { gw_ms_user, gw_ms_auth } from '@core';
import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class SecurityService {
  constructor(private http: _HttpClient) {}

  public queryLookUp(typeCode: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/common/lookup/query/${typeCode}`);
  }

  public queryMenuIcon(): Observable<any> {
    return this.queryLookUp('menu_icon');
  }

  public queryUserUrl() {
    return `${gw_ms_user}/security/user/query`;
  }

  public queryUser(params: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/user/query`, params);
  }

  public queryUserRole(userId: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/user/role/query?userId=${userId}`);
  }
  public saveUserRole(userIds: any, roleIds: any[]): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/user/role/save?userIds=${userIds}&roleIds=${roleIds}`);
  }

  public queryDataPermission(username: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/user/data/permission/query/${username}`);
  }

  public saveDataPermission(username: any, phoneDecrypted: boolean): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/user/data/permission/save?username=${username}&phoneDecrypted=${phoneDecrypted}`);
  }

  public queryRoleUrl() {
    return `${gw_ms_user}/security/role/query`;
  }
  public queryRole(params: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/role/query`, params);
  }

  public queryMenuUrl() {
    return `${gw_ms_user}/security/menu/query`;
  }

  public queryMenuTree(): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/menu/tree/query`);
  }

  public saveMenuTree(body: any): Observable<any> {
    return this.http.post(`${gw_ms_user}/security/menu/tree/save`, body);
  }
  public dropMenuTree(id: any, newPid: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/menu/tree/drop?id=${id}&newPid=${newPid}`);
  }

  public deleteMenuTree(id: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/menu/tree/delete?id=${id}`);
  }
  public queryMenuIdByRole(roleId: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/role/menu/roleId/${roleId}`);
  }
  public saveRoleMenus(roleIds: any, menuIds: any[]): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/role/menu/save?roleIds=${roleIds}&menuIds=${menuIds}`);
  }

  public queryMenu(params: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/menu/query`, params);
  }

  public saveUser(body: any): Observable<any> {
    return this.http.post(`${gw_ms_user}/security/user/save`, body);
  }
  public updateUserPassword(body: any): Observable<any> {
    return this.http.post(`${gw_ms_user}/security/user/password/update`, body);
  }

  public saveRole(body: any): Observable<any> {
    return this.http.post(`${gw_ms_user}/security/role/save`, body);
  }
  public saveMenu(body: any): Observable<any> {
    return this.http.post(`${gw_ms_user}/security/menu/save`, body);
  }

  public deleteRole(id: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/role/delete/${id}`);
  }
  public deleteRoleMenu(roleIds: any): Observable<any> {
    return this.http.get(`${gw_ms_user}/security/role/menu/delete?roleIds=${roleIds}`);
  }
}
